package com.manager.seat.controller;

import com.manager.seat.model.TbTodoList;
import com.manager.seat.service.TodosService;
import com.manager.seat.util.JsonResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * @ClassName IoginController
 * @Description TODO
 * @date 2022/10/29 11:03
 * @Version 1.0
 */
@RestController
@RequestMapping(value = "/todos/manager")
@Slf4j
public class TodosController {
    @Autowired
    private TodosService todosService;


    @GetMapping("/todo/{type}")
    public JsonResult<List<TbTodoList>> getAllTodo(
            @PathVariable("type") String type) {
        List<TbTodoList> todos = todosService.getAllTodo(type);
        return new JsonResult<>(todos);
    }
    @ResponseBody
    @PostMapping("/add")
    public JsonResult<TbTodoList> add(@RequestBody TbTodoList param) {
        Assert.hasLength(param.getName(), "用户名或者学号不能为空");
        param.setType("1");

        todosService.add(param);
        return new JsonResult<>(param);
    }
    @PostMapping("/update")
    public JsonResult<TbTodoList> update(@RequestBody TbTodoList param) {
        todosService.update(param);
        return new JsonResult<>(param);
    }


    @GetMapping("/delete/{id}")
    public JsonResult<Long> delete(@PathVariable("id") Long id) {
        todosService.delete(id);
        return new JsonResult(id);
    }




}
